/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package core.version;

/**
 *
 * @author Dung Pham
 */
public class Version implements Comparable<Version> {

    private String versionName = "";
    private int version = 0;
    private int versionSub1 = 0;
    private int versionSub2 = 0;
    private int versionNumber = 0;

    /**
     *
     * @param versionName
     */
    public Version(String versionName) {
        this.versionName = versionName;
        this.version = Integer.parseInt(versionName.substring(0, 1));
        // bo dau cham ke tiep di la subversion 1
        if (versionName.length() >= 3) {
            this.versionSub1 = Integer.parseInt(versionName.substring(2, 3));
            if (versionName.length() >= 5) {
                // bo tiep dau cham nua la subversion 2
                this.versionSub2 = Integer.parseInt(versionName.substring(4, 5));
            }
        }
        this.versionNumber = version * 100 + this.versionSub1 * 10 + this.versionSub2;
    }

    @Override
    public String toString() {
        return versionName;
    }

    /**
     * 0:equal; 1:bigger;-1:smaller
     *
     * @param o
     * @return
     */
    @Override
    public int compareTo(Version o) {
        int result = 0;
        if (this.versionNumber == o.versionNumber) {
            result = 0;
        } else if (this.versionNumber > o.versionNumber) {
            result = 1;
        } else {
            result = -1;
        }
        return result;
    }
}
